package com.wxjfkg.sdk.sms;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wxjfkg.sdk.HttpApiClient;
import com.wxjfkg.sdk.http.HttpApiResponse;
import com.wxjfkg.sdk.request.InternalHttpApiRequest;
import com.wxjfkg.sdk.sms.model.SmsEnvelope;
import com.wxjfkg.sdk.sms.model.SmsResponse;

/**
 * 短信发送工具类
 * 
 * @author GuoRui
 *
 */
public class SmsUtils {

	private static Logger logger = LoggerFactory.getLogger(SmsUtils.class);
	
	/**
	 * 发送单条短信
	 * 
	 * @param envelope
	 * @return
	 */
	public static SmsResponse send(SmsEnvelope envelope) {
		if(StringUtils.isBlank(envelope.getUrl())) {
			logger.error("短信接口地址参数不能为空");
			throw new IllegalArgumentException("envelope url can't be null.");
		}
		
		InternalHttpApiRequest<SmsEnvelope> request = new InternalHttpApiRequest<SmsEnvelope>(envelope.getUrl());
		request.setEntity(envelope);
		
		HttpApiClient apiClient = new HttpApiClient();
		HttpApiResponse<SmsResponse> response = apiClient.execute(request, SmsResponse.class);
		return response.getEntity();
	}
	
}
